<%@page import="html.ATarget"%>
<%@page import="localization.Localization"%>
<%@page import="html.InputType"%>
<%@page import="strategies.Strategy"%>
<%@page import="strategies.StrategySequence"%>
<%@page import="strategies.WebContext"%>
<%@page import="common.ParamStorage"%>
<%@page import="html.XHtmlFormatter"%>
<%@page import="common.Application"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%!    
    Application app = Application.getInstance();
    short currentTable = 0;
    XHtmlFormatter provider;
%>

<%
            ParamStorage storage = new ParamStorage(request);
            provider = new XHtmlFormatter(out);
            provider.startHtml();
            provider.startHead();
            provider.writeMeta("Content-Language", "en-US");
            provider.writeMeta("Content-Type", "text/xhtml+xml; charset=iso-8859-1");
            provider.writeLink("stylesheet", "text/css", "style.css");
            provider.writeTitle(Localization.getString(app.getTitle()) + " > " + Localization.getString("EditPage"));
            provider.endHead();
            provider.startBody();
            provider.startDiv("header");
            provider.startDiv();
            provider.writeH1(Localization.getString("EditPage"));
            provider.endDiv();
            provider.endDiv();
            provider.startForm("index.jsp", "post");
            provider.startDiv("control");
            if (storage.hasParam("table-selection")) {
                currentTable = Short.parseShort(storage.getParam("table-selection"));
            }
            provider.writeInput(InputType.hidden, "table-selection", "", "", Short.toString(currentTable));
            provider.startDiv("", "optionsPanel");
            provider.writeInput(InputType.submit, "back", "back", "", Localization.getString("Back"));
            provider.writeInput(InputType.submit, "save", "save", "", Localization.getString("Save"));
            provider.startA(Localization.getHelpFileName(), ATarget.Blank);
            provider.startDiv("help");
            provider.putImage("pdf.png", "large");
            provider.echo(Localization.getString("GetHelp"));
            provider.endDiv();
            provider.endA();
            provider.endDiv();
            provider.endDiv();
            provider.startDiv("content");

            WebContext ctx = new WebContext(provider, storage);
            ctx.setUid(currentTable);
            StrategySequence strategySequence = new StrategySequence(request, true);
            Iterable<Strategy> sequence = strategySequence.getSequence();
            for (Strategy s: sequence) {
                s.execute(ctx);
            }
            
            provider.endDiv();
            provider.endForm();
            provider.startDiv("footer");
            provider.writeP("center", Localization.getString("Copyright"));
            provider.endDiv();
            provider.endBody();
            provider.endHtml();
%>
